package com.example.clock;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class CountDialog extends Dialog {
    private String date;
    private int countOfMonth;
    private int timeCountOfMonth;
    private TextView detail;
    private EditText moneyOfHour;
    private TextView result;
    public void setCountOfMonth(int countOfMonth) {
        this.countOfMonth = countOfMonth;
    }

    public void setTimeCountOfMonth(int timeCountOfMonth) {
        this.timeCountOfMonth = timeCountOfMonth;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public CountDialog(@NonNull Context context) {
        super(context);
    }

    public CountDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected CountDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.count_dialog);
        detail = (TextView) findViewById(R.id.detail);
        moneyOfHour = (EditText) findViewById(R.id.moneyOfHour);
        result = (TextView) findViewById(R.id.result);

        detail.setText(date+"共累计工作："+countOfMonth+"天 \t 计："+timeCountOfMonth+"时");
        moneyOfHour.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                try {
                    result.setText(""+Integer.parseInt(moneyOfHour.getText().toString())*timeCountOfMonth);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
}
